package com.facebook.app.client;

import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;

public class LoginContent {
	
	private final FacebookCookie authCookie = new FacebookCookie();
	
	private final Label loginStatus = new Label();
	
	public FacebookCookie getAuthCookie() {
		return authCookie;
	}
	
	public void display(RootPanel rootPanel) {
		
		String html = "";

		authCookie.load();
		
		if (isLoggedIn()) {
			loginStatus.setText("You are logged in");
			
			// embed hidden iframe with Facebook API init-script 
			html = "<iframe src=\"FacebookLogin.html\" name=\"Login\" height=\"0\" width=\"0\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\"><p></p></iframe>";
			
			
		} else {
			loginStatus.setText("Please log in");
			
			// embed visible iframe with Facebook API init-script
			html = "<iframe src=\"FacebookLogin.html\" name=\"Login\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\"><p></p></iframe>";
			
			
		}
		
		HTML facebook_button = new HTML(html);
		
		
		rootPanel.add(loginStatus);
		rootPanel.add(facebook_button);
	}
	
	public boolean isLoggedIn() {
		return authCookie.isValid();
	}
}
